<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	xmlns:p="http://primefaces.org/ui"
	xmlns:cc="http://java.sun.com/jsf/composite"
	xmlns:hmrTable="http://java.sun.com/jsf/composite/table"
	xmlns:hmrList="http://java.sun.com/jsf/composite/list"
	xmlns:hmrDetail="http://java.sun.com/jsf/composite/detail"	>

<cc:interface>
	<cc:attribute name="handler"	type="com.hemerasolutions.v2trainer.component.interfaces.detail.ModalityDetailsCompInterface" required="true"/>
	<cc:attribute name="editable"	type="java.lang.Boolean" required="true" default="false"/>
	<cc:attribute name="update"		type="java.lang.String" required="false"/>
</cc:interface>

<cc:implementation>
	<ui:param name="separator" value=":"/>
	<ui:param name="jseparator" value="\\:"/>

	<span id="#{cc.clientId}" >
	
		<p:tabView id="tabModality" style="border:none;min-height:99%;width:99%;position:relative" cache="false"
			rendered="#{cc.attrs.handler.modality != null}"  effect="slide"   widgetVar="wtabModality"  >
			<p:tab id="tabModalityData"  title="#{msgs.BasicData} - #{msgs.Version}: #{cc.attrs.handler.modality.version} " titleStyleClass="ui-widget"  >
				<h:form id="modalityDataForm" prependId="false">
					<h:panelGrid columns="2" cellpadding="2" columnClasses="top-align,top-align" style="min-height:90%;width:100%"  > 
						<h:column>
							<h:panelGrid columns="2" cellpadding="2" > 
					            <h:outputLabel value="#{msgs.Name} :" for="modalityName" />
					            <p:inputText id="modalityName"     value="#{cc.attrs.handler.modality.name}" maxlength ="20" size="20" required="true" requiredMessage="#{msgs.ModalityNameObligatory}"/>
					
					            <h:outputLabel value="#{msgs.ModalityType} :" for="modalityType" />
					            <p:selectOneMenu id="modalityType" value="#{cc.attrs.handler.modality.trainingType}" converter="#{ttConverter}" valueChangeListener="#{cc.attrs.handler.onTrainingTypeChange}"   >
					            	<f:selectItems value="#{cc.attrs.handler.trainingTypes}"  var="trainingType" itemLabel="#{msgs[trainingType.name]}" itemValue="#{trainingType}" />
									<p:ajax listener="#{cc.attrs.handler.trainingTypeChanged }" update="panelExecutionTypes, panelVolumes, @this " />
					            </p:selectOneMenu>
					
								<h:outputLabel value="#{msgs.Description} :" for="modalityDescription" />
								<p:inputTextarea id="modalityDescription" rows="4" cols="50" immediate="true"
									counter="counter" maxlength="180"
									counterTemplate="{0} #{msgs.CharsRemaining}" autoResize="false"
									value="#{ cc.attrs.handler.modality.description}">
									<p:ajax event="change" update="@this"  />
								</p:inputTextarea>
								<p:spacer />
								<h:outputText id="counter" />
							
								<h:outputLabel 	value="#{msgs.Library} :"		for="modalityLibrary" rendered="#{cc.attrs.handler.modality.id == null}" />
								<p:selectOneMenu id="modalityLibrary" value="#{cc.attrs.handler.versionableModality.library}"	  rendered="#{cc.attrs.handler.modality.id == null}" converter="#{libraryConverter}">
					            	<f:selectItems value="#{cc.attrs.handler.activeUser.librarys}" var="library" itemLabel="#{library.name}" itemValue="#{library}"  />
								</p:selectOneMenu>
				
								<h:outputLabel 	value="#{msgs.Library} :"		for="modalitySavedLibrary" rendered="#{cc.attrs.handler.modality.id != null}"  />
								<p:inputText id="modalitySavedLibrary" value="#{cc.attrs.handler.versionableModality.library.name}"  disabled="true" rendered="#{cc.attrs.handler.modality.id != null}" />
													
								<h:outputLabel 	value="#{msgs.CreatedAt} :"		for="modalityCreatedAt" rendered="#{cc.attrs.handler.modality.id != null}" />
								<p:inputText  	id="modalityCreatedAt" 	value="#{cc.attrs.handler.modality.createdAt}" disabled="true" rendered="#{cc.attrs.handler.modality.id != null}"  >
									<f:convertDateTime locale="pt" dateStyle="long" pattern="dd/MM/yyyy HH:mm" rendered="#{cc.attrs.handler.modality.id != null}" />
								</p:inputText>
					
								<h:outputLabel 	value="#{msgs.ChangedAt} :"		for="modalityChangedAt" rendered="#{cc.attrs.handler.modality.id != null}" />
								<p:inputText  	id="modalityChangedAt" 	value="#{cc.attrs.handler.modality.lastChange}" disabled="true"  rendered="#{cc.attrs.handler.modality.id != null}">
									<f:convertDateTime locale="pt" dateStyle="long" pattern="dd/MM/yyyy HH:mm" />
								</p:inputText>
							</h:panelGrid>			
						</h:column>
						<h:column>
							<p:panel id="panelExecutionTypes" header="#{msgs.ExecutionsTypes}" style="margin-left:100px;width:500px" styleClass="">
								<p:pickList id="pickExecution" value="#{cc.attrs.handler.executions}" var="execution"  required="true" requiredMessage="#{msgs.AtLeastOneExecutionIsRequired}"
									itemLabel="#{msgs[execution.name]}" itemValue="#{execution}" converter="#{genericConverter}">
									 <p:ajax event="transfer" update=":growl,pickExecution" listener="#{cc.attrs.handler.onChangeExecution}" />
								</p:pickList>
								<p:commandButton value="#{msgs.DefaultIntensityZones}" actionListener="#{cc.attrs.handler.toIntensityModality}" oncomplete="wmodalityID_#{cc.id}.show();"
									process="@parent" update=":#{cc.clientId}:modalityID,:growl"   />
							</p:panel>
							<p:panel id="panelVolumes" header="#{msgs.Volumes}" style="margin-left:100px;margin-top:10px;width:500px">
								<p:pickList id="pickVolumes" value="#{cc.attrs.handler.volumes}" var="volume"   required="true" requiredMessage="#{msgs.AtLeastOneVolumeIsRequired}"
									itemLabel="#{msgs[volume.name]}" itemValue="#{volume}" converter="#{genericConverter}"  >
									 <p:ajax event="transfer" listener="#{cc.attrs.handler.onChangeVolume}" />
								</p:pickList>
							</p:panel>
						</h:column>
					</h:panelGrid>		
					<div align="left" style="position:absolute;bottom:0;left:0;" >
						<p:outputPanel layout="block" rendered="#{cc.attrs.handler.modality != null}">
							<p:commandButton id="saveButton"  	value="#{msgs.Save}"		actionListener="#{cc.attrs.handler.saveModality}"  	process=":#{cc.clientId}"	 		
								ajax="true"	update="#{cc.attrs.update}"		icon="ui-icon-disk"		rendered="#{cc.attrs.handler.modality.id != null}" />
							<p:commandButton id="createButton" 	value="#{msgs.Create}"	actionListener="#{cc.attrs.handler.createModality}"		process=":#{cc.clientId}" 
								ajax="true"	update="#{cc.attrs.update}"		icon="ui-icon-document"	rendered="#{cc.attrs.handler.modality.id == null}" />
							<p:spacer width="50px"/>	
							<p:commandButton  value="#{msgs.Cancel}" update="#{cc.attrs.update}"	action="#{cc.attrs.handler.cancelChange}"	icon="ui-icon-cancel"/>
							<p:blockUI block=":#{cc.clientId}:tabModality" trigger="createButton saveButton" />
						</p:outputPanel>
					</div>	 					

				</h:form>
			</p:tab>
			<p:tab id="tabModalityExercise" title="#{msgs.IntensityZones}  - #{msgs.Version}: #{cc.attrs.handler.modality.version}" titleStyleClass="ui-widget"   >
				<hmrTable:exerciseTable id="exerciseTable" handler="#{cc.attrs.handler.exerciseTableComp}" editable="#{cc.attrs.editable}"/>
				<p:outputPanel layout="block" rendered="#{cc.attrs.handler.modality != null}" style="position:absolute;bottom:0px;left:0px">
					<p:commandButton value="#{msgs.Save}"	icon="ui-icon-disk" 	process="exerciseTable"		rendered="#{cc.attrs.handler.modality.id != null}"
						oncomplete="$(' ##{fn:replace(cc.clientId, separator, jseparator)}\\:tabModality\\:saveButton').click()" />
					<p:commandButton value="#{msgs.Create}"	icon="ui-icon-document"	process="exerciseTable"		rendered="#{cc.attrs.handler.modality.id == null}" 
						oncomplete="$(' ##{fn:replace(cc.clientId, separator, jseparator)}\\:tabModality\\:createButton').click()" />
					<p:spacer width="50px" height="1px"/>	
					<p:commandButton  value="#{msgs.Cancel}" update="#{cc.attrs.update}"	action="#{cc.attrs.handler.cancelChange}"	icon="ui-icon-cancel"/>
				</p:outputPanel>
			</p:tab>
		</p:tabView>
	</span>

	<p:dialog id="modalityID" header="#{msgs.DefaultIntensityZones}" style="width:900px" dynamic="true"  modal="true" appendTo="@(body)" widgetVar="wmodalityID_#{cc.id}" >
		<h:form id="modalityItensityForm" prependId="false">
			<hmrList:modalityIZList handler="#{cc.attrs.handler.modalityIZList}"  editable="true" />

			<p:commandButton type="button" value="#{msgs.Close}" onclick="wmodalityID_#{cc.id}.hide();"/>
		</h:form>
	</p:dialog>
	

</cc:implementation>
</html>	